package com.zshield.util;

import javax.swing.text.DateFormatter;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.OffsetDateTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.Random;

public class Etime {
    public static final DateTimeFormatter DATETIME_FORMATTER =  DateTimeFormatter.ofPattern("yyyy-MM-dd\'T\'HH:mm:ss+08:00");
    public static final DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd");
    public static final DateTimeFormatter DATE_FORMATTER_INDEX = DateTimeFormatter.ofPattern("yyyy.MM");
    public static final DateTimeFormatter TIME_FORMATTER = DateTimeFormatter.ofPattern("1971-01-01\'T\'HH:mm:ss+08:00");

    public String zoneParse(String time) {
        OffsetDateTime offDateTime = OffsetDateTime.parse(time);
        ZoneOffset zoneOffset = ZoneOffset.of("+08:00");
        OffsetDateTime offsetDateTime = offDateTime.withOffsetSameInstant(zoneOffset);
        return offsetDateTime.format(Etime.DATETIME_FORMATTER);
    }

    public static void main(String[] args) {
        String s1 = "2018-08-20T06:09:58";
        String s2 = "2018-08-20T15:09:58";
        DateTimeFormatter dtf =  DateTimeFormatter.ofPattern("yyyy-MM-dd\'T\'HH:mm:ss");
        DateTimeFormatter dtf1 =  DateTimeFormatter.ofPattern("yyyy-MM-dd");

        LocalDateTime dateTime1 = LocalDateTime.parse(s1, dtf);
        LocalDateTime dateTime2 = LocalDateTime.parse(s2, dtf);

        LocalDate localDate = dateTime2.toLocalDate();
        String format = localDate.format(dtf1);

        int hour1 = dateTime1.getHour();
        int hour2 = dateTime2.getHour();
        String res;
        while (hour2 > hour1){
            res = hour1 < 10 ? "0" + hour1 : "" + hour1;
            System.out.println(format + "T" + res);
            hour1 ++;
        }

    }
}
